<#import "../tpl/pageTep.ftl" as page>
<@page.pageBase currentMenu="充值管理">
<style>
  .form-horizontal .controls {
    line-height: 40px;
    height: 40px;
    margin-left: 3px;
  }

  .button-primary {
    margin-left: 20px;
  }
</style>
   <form id="searchForm" class="form-panel" action="${basepath}/rest/manage/balance/selectBalancePage">
     <ul class="panel-content">
       <li>
         <div class="control-group span5">
           <div class="search-controls  controls">
             <input type="text" name="userName" id="userName" value="" placeholder="搜索关键字">
           </div>
         </div>
         <div>
           <label class="time-label control-label">起始日期：</label>
           <div class="time-controls controls">
             <input name="startDate" class="input-small calendar" type="text" style="width: 80px;"><label>
             &nbsp;-&nbsp;</label>
             <input name="endDate" class="input-small calendar" type="text" style="width: 80px;">
           </div>
           <button type="submit" class="button  button-primary">
             查询
           </button>
           <a class="button button-primary" href="javascript:rechargeBtn()">
             设置充值档次
           </a>
         </div>
       </li>
     </ul>
   </form>
<div id="grid"></div>
<#-------------------------------------------------------设置充值档次 begin-------------------------------------------------------->
<div id="editContent" style="display:none;">
  <form id="editForm" class="form-horizontal" action="${basepath}/rest/manage/systemSetting/updateJson" method="post">
    <input type="hidden" class="control-text span-width span10" name="id" value="">
    <div class="row">
      <div class="control-group span16">
        <label class="control-label">一档充值金额：</label>
        <div class="controls">
          <input type="text" class="input-normal control-text" name="firstMoney"
                 data-rules="{required : true,number:true}">
        </div>
      </div>
      <div class="control-group span16">
        <label class="control-label">一档返利金额：</label>

        <div class="controls">
          <input type="text" class="input-normal control-text" name="firstRebate"
                 data-rules="{required : true,number:true}">
        </div>
      </div>
      <div class="control-group span16">
        <label class="control-label">二档充值金额：</label>

        <div class="controls">
          <input type="text" class="input-normal control-text" name="secondMoney"
                 data-rules="{required : true,number:true}">
        </div>
      </div>
      <div class="control-group span16">
        <label class="control-label">二档返利金额：</label>

        <div class="controls">
          <input type="text" class="input-normal control-text" name="secondRebate"
                 data-rules="{required : true,number:true}">
        </div>
      </div>
      <div class="control-group span16">
        <label class="control-label">三档充值金额：</label>

        <div class="controls">
          <input type="text" class="input-normal control-text" name="thirdMoney"
                 data-rules="{required : true,number:true}">
        </div>
      </div>
      <div class="control-group span16">
        <label class="control-label">三档返利金额：</label>

        <div class="controls">
          <input type="text" class="input-normal control-text" name="thirdRebate"
                 data-rules="{required : true,number:true}">
        </div>
      </div>
      <div class="control-group span16">
        <label class="control-label">四档充值金额：</label>

        <div class="controls">
          <input type="text" class="input-normal control-text" name="fourthMoney"
                 data-rules="{required : true,number:true}">
        </div>
      </div>
      <div class="control-group span16">
        <label class="control-label">四档返利金额：</label>
        <div class="controls">
          <input type="text" class="input-normal control-text" name="fourthRebate"
                 data-rules="{required : true,number:true}">
        </div>
      </div>
    </div>
  </form>
</div>
<#-------------------------------------------------------设置充值档次 end-------------------------------------------------------->
<script>
  var Grid = BUI.Grid,
    Store = BUI.Data.Store,
    columns = [
      {title: '序号', dataIndex: 'id', elCls: 'center', width: '10%'},
      {title: '充值人', dataIndex: 'userName', elCls: 'center', width: '20%'},
      {title: '充值时间', dataIndex: 'createTime', elCls: 'center', width: '20%'},
      {title: '充值金额', dataIndex: 'money', elCls: 'center', width: '20%'},
      {title: '赠送金额', dataIndex: 'sendMoney', elCls: 'center', width: '20%'},

      {
        title: '操作', dataIndex: 'id', elCls: 'center', width: '10%', renderer: function (value, obj, index) {
          return '<a href="javascript:deleteOne(' + value + ')">删除</a>';
        }
      }
    ];
  var store = new Store({
              url: '/rest/manage/balance/selectBalancePage',
              autoLoad: true, //自动加载数据
              params: { //配置初始请求的参数
                  length: '10',
                  status: $("#status").val()
              },
              pageSize: 10,	// 配置分页数目
              root: 'list',
              totalProperty: 'total'
          }),
    grid = new Grid.Grid({
      render: '#grid',
      columns: columns,
      loadMask: true, //加载数据时显示屏蔽层
      store: store,
      plugins: [Grid.Plugins.CheckSelection], // 插件形式引入多选表格
      // 底部工具栏
      bbar: {
        pagingBar: true
      }
    });

  grid.render();
  /*--------------------------------模糊查询---------------------------------------------*/
  var form = new BUI.Form.HForm({
    srcNode: '#searchForm'
  }).render();

  form.on('beforesubmit', function (ev) {
    //序列化成对象
    var obj = form.serializeToObject();
    obj.start = 0; //返回第一页
    store.load(obj);
    return false;
  });
  /*--------------------------------模糊查询---------------------------------------------*/
  /*--------------------------------删除---------------------------------------------*/
  //删除单个用户
  function deleteOne(value) {
    BUI.Message.Confirm('确认要删除吗？', function () {
      $.ajax({
        type: 'POST',
        url: '${basepath}/rest/manage/balance/deleteJson',
        dataType: 'json',
        data: {
          id: value
        },
        success: function () {
          var obj = form.serializeToObject();
          obj.start = 0; //返回第一页
          store.load(obj);
        }
      });
    }, 'question');
  }

  /*--------------------------------删除---------------------------------------------*/
  /*--------------------------------设置充值档次 begin---------------------------------------------*/
  var editForm = new BUI.Form.Form({
    srcNode: '#editForm',
    submitType: 'ajax',
    callback: function (data) {
      var obj = new Object();
      obj.start = 0; //返回第一页
      store.load(obj);
      editDialog.close();
    }
  });
  editForm.render();

  var editDialog = new BUI.Overlay.Dialog({
    width: 400,
    contentId: 'editContent',
    success: function () {
      if (editForm.isValid()) {
        editForm.ajaxSubmit();
      } else {
        editForm.valid();
      }
    }
  });
  //查询充值档次
  function rechargeBtn() {
    $.ajax({
      type: "POST",
      dataType: "json",
      url: "${basepath}/rest/manage/systemSetting/selectSystemSetting",
      success: function (data) {
        var form = $("#editForm")[0];
        BUI.FormHelper.setFields(form, data.data);
        editDialog.show();
      }
    });
  }

  /*--------------------------------设置充值档次 end---------------------------------------------*/
</script>

</@page.pageBase>
